package com.lib;

import android.graphics.Color;
import android.os.Bundle;
import android.support.annotation.LayoutRes;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.MenuItem;

import com.codebox.R;

public class BaseActivity extends AppCompatActivity {
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		//getSupportActionBar().setDisplayHomeAsUpEnabled(true);
	    /*DrawerArrowDrawable drawerArrow = new DrawerArrowDrawable(this) {
            @Override
            public boolean isLayoutRtl() {
                return false;
            }
        };
        drawerArrow.setProgress(1.f);
        try {
            Method setHomeAsUpIndicator = ActionBar.class.getDeclaredMethod("setHomeAsUpIndicator",
                Drawable.class);
            setHomeAsUpIndicator.invoke(getActionBar(), drawerArrow);
            return;
        } catch (Exception e) {
            Log.e("BaseActivity", "setActionBarUpIndicator error", e);
        }*/
	}

    protected Toolbar toolbar;
    protected void setConttentViewAndToolbar(@LayoutRes int layoutId,@Nullable String title){
        setContentView(layoutId);
        toolbar= (Toolbar) findViewById(R.id.tl_custom);
        toolbar.setTitle(title);//设置Toolbar标题
        toolbar.setTitleTextColor(Color.parseColor("#ffffff")); //设置标题颜色
        setSupportActionBar(toolbar);
    }

    @Override
    public void setTitle(CharSequence title) {
        if(toolbar!=null)
            toolbar.setTitle(title);
    }

    protected void showBackHomeButton(){
        ////设置返回键可用
        getSupportActionBar().setHomeButtonEnabled(true);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        if (item.getItemId() == android.R.id.home) {
            finish();
        }
        return super.onOptionsItemSelected(item);
    }	
}
